// pages/announcements/announcement.js
import request from "../../utils/request.js";
import themeManager from "../../utils/theme.js";
Page(themeManager.enhancePage({
  data: {
    announcements: [],
    loading: true,
    currentTheme: 'dark'
  },
  onLoad() {
    this.loadAnnouncements();
  },
  loadAnnouncements() {
    this.setData({ loading: true });
    request.get("/announcements").then(res => {
      this.setData({ announcements: res.data.items, loading: false });
    }).catch(() => {
      this.setData({ announcements: [], loading: false });
    });
  },
  toAnnouncementDetail(event) {
    const announcementId = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/announcement/announcement?announcementId=${announcementId}`
    });
  }
}));